package com.corona.game.util;

import com.badlogic.gdx.Gdx;
import com.badlogic.gdx.files.FileHandle;
import com.badlogic.gdx.graphics.Color;
import com.badlogic.gdx.graphics.Pixmap;
import com.badlogic.gdx.graphics.Texture;
import com.corona.Game;
import com.corona.game.util.texture.StaticTextures;
import java.util.HashMap;

/* loaded from: pokewilds.jar:com/pkmngen/game/util/TextureCache.class */
public class TextureCache {
    public static Texture currTexture;
    public static HashMap<FileHandle, Texture> textMap = new HashMap<>();
    public static HashMap<Texture, Texture[]> effectsTextMap = new HashMap<>();
    public static HashMap<Texture, Color[]> colorsTextMap = new HashMap<>();
    public static HashMap<String, Texture> eggTextures = new HashMap<>();
    public static SpriteProxy maleSymbol = new SpriteProxy(Color.WHITE, new Texture(Gdx.files.internal("male_symbol1.png")), 0, 0, 8, 8);
    public static SpriteProxy femaleSymbol = new SpriteProxy(Color.WHITE, new Texture(Gdx.files.internal("female_symbol1.png")), 0, 0, 8, 8);
    public static SpriteProxy shinySymbol = new SpriteProxy(Color.WHITE, new Texture(Gdx.files.internal("shiny.png")), 0, 0, 8, 8);
    public static SpriteProxy maleSymbolInverse = new SpriteProxy(Color.BLACK, new Texture(Gdx.files.internal("male_symbol1_inverse.png")), 0, 0, 8, 8);
    public static SpriteProxy femaleSymbolInverse = new SpriteProxy(Color.BLACK, new Texture(Gdx.files.internal("female_symbol1_inverse.png")), 0, 0, 8, 8);
    public static SpriteProxy shinySymbolInverse = new SpriteProxy(Color.BLACK, new Texture(Gdx.files.internal("shiny_inverse.png")), 0, 0, 8, 8);

    public static Texture get(final Pixmap pixmap) {
        if (Thread.currentThread() != Game.staticGame.gameThread) {
            Runnable runnable = new Runnable() { // from class: com.corona.game.util.TextureCache.1
                @Override // java.lang.Runnable
                public void run() {
                    try {
                        TextureCache.currTexture = new Texture(pixmap);
                    } catch (Exception e) {
                        e.printStackTrace();
                    }
                    synchronized (this) {
                        notify();
                    }
                }
            };
            Gdx.app.postRunnable(runnable);
            try {
                synchronized (runnable) {
                    runnable.wait();
                }
            } catch (InterruptedException e) {
                e.printStackTrace();
            }
        } else {
            currTexture = new Texture(pixmap);
        }
        return currTexture;
    }

    public static SmolSprite getTileSprite(String name, int srcX, int srcY, int width, int height) {
        SmolSprite sprite = getTileSprite(name);
        sprite.setRegion(srcX, srcY, width, height);
        return sprite;
    }

    public static SmolSprite getTileSprite(String name, int width, int height) {
        return getTileSprite(name, 0, 0, width, height);
    }

    public static SmolSprite getTileSprite(String name) {
        return new SmolSprite(StaticTextures.getOrCreate(name));
    }

    public static Texture get(final FileHandle file) {
        if (!textMap.containsKey(file)) {
            if (Thread.currentThread() != Game.staticGame.gameThread) {
                Runnable runnable = new Runnable() { // from class: com.corona.game.util.TextureCache.2
                    @Override // java.lang.Runnable
                    public void run() {
                        try {
                            TextureCache.textMap.put(file, new Texture(file));
                        } catch (Exception e) {
                            e.printStackTrace();
                        }
                        synchronized (this) {
                            notify();
                        }
                    }
                };
                Gdx.app.postRunnable(runnable);
                try {
                    synchronized (runnable) {
                        runnable.wait();
                    }
                } catch (InterruptedException e) {
                    e.printStackTrace();
                }
            } else {
                FileHandle moddedFile = Gdx.files.local("mods/" + file.path());
                try {
                    if (moddedFile.exists()) {
                        textMap.put(file, new Texture(moddedFile));
                    } else {
                        textMap.put(file, new Texture(file));
                    }
                } catch (Exception e2) {
                    e2.printStackTrace();
                    textMap.put(file, new Texture(Gdx.files.internal("tiles/blank3.png")));
                }
            }
        }
        return textMap.get(file);
    }
}
